pub mod auth;
pub mod metainfo;

use serde::{Deserialize, Serialize};
use uuid::Uuid;
use sqlx::FromRow;

#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct User {
    pub user_id: i64,
    pub username: String,
    pub password_hash: String,
    pub role: String,
    pub created_at: chrono::NaiveDateTime,
    pub updated_at: chrono::NaiveDateTime,
}

#[derive(Deserialize)]
pub struct CreateUserRequest {
    pub username: String,
    pub password: String,
    pub role: String,
}

// 登录用户的角色
#[derive(Serialize, Deserialize, PartialEq)]
pub enum Role {
    Admin,
    User,
    Guest
}

impl Role {
    pub fn to_str(&self) -> &str {
        match self {
            Role::Admin => "admin",
            Role::User => "user",
            Role::Guest => "guest",
        }
    }

    pub fn from_str(s: &str) -> Option<Role> {
        match s {
            "admin" => Some(Role::Admin),
            "user" => Some(Role::User),
            "guest" => Some(Role::Guest),
            _ => None,
        }
    }
}

#[derive(Deserialize)]
pub struct UpdateUserPasswordRequest {
    pub new_password: String,
}

#[derive(Deserialize)]
pub struct GetUserByUsernameRequest {
    pub username: String,
}

#[derive(Deserialize)]
pub struct UpdateUserRoleRequest {
    pub new_role: String,
}

#[derive(Deserialize)]
pub struct DeleteUserRequest {
    pub user_id: i64,
}

#[derive(Deserialize)]
pub struct UserFavorite {
    pub user_id: i64,
    pub song_id: i64,
}